package com.sqx.modules.app.controller.app;

import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.app.entity.UserEntity;
import com.sqx.modules.app.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author fang
 * @date 2020/7/30
 */
@RestController
@Api(value = "用户管理", tags = {"用户管理"})
@RequestMapping(value = "/app/user/")
public class AppUserController {
    @Autowired
    UserService userService;

    @Login
    @PostMapping("updateUserEntity")
    public Result updateUserEntity(@RequestAttribute("userId") Long userId, Integer userType) {
        UserEntity userEntity = new UserEntity();
        userEntity.setUserId(userId);
        userEntity.setUserType(userType);
        return userService.updateById(userEntity) ? Result.success() : Result.error();
    }
    @Login
    @ApiOperation("用户推广信息")
    @GetMapping(value = "getExtensionData")
    public Result getExtensionData(@RequestAttribute("userId") Long userId) {
        return Result.success().put("data", userService.getExtensionData(userId));
    }

    @Login
    @ApiOperation("获取推广用户列表")
    @GetMapping(value = "getExtensionList")
    public Result getExtensionList(@RequestAttribute("userId") Long userId,Integer type, Integer page, Integer limit) {
        return Result.success().put("data", userService.getExtensionList(userId,type, page, limit));
    }


    @Login
    @ApiOperation("获取邀请的用户收益列表")
    @GetMapping(value = "getProfitList")
    public Result getProfitList(@RequestAttribute("userId") Long userId,Integer type, Integer page, Integer limit) {
        return Result.success().put("data", userService.getProfitList(userId,type, page, limit));
    }
    @Login
    @RequestMapping(value = "/selectInviteCount", method = RequestMethod.GET)
    @ApiOperation("查看我邀请的人员数量")
    @ResponseBody
    public Result selectInviteCount(Integer state,@RequestAttribute Long userId){
        return Result.success().put("data",userService.selectInviteCount(state,userId));
    }
}